﻿
/**
*@description 上传附件表单
*/
Chenxin.UI.UploadAttachForm=Chenxin.extend(Chenxin.UI.FormCommon,{	
	actionUrl:'/service/logic/ShowListLitigation.ashx',
	id:'divUploadattach',
	renderTo:'divUploadattach',
	jqmWidth:500,
	createForm:function(){
		return Chenxin.FormCommon.UploadAttachForm(this.id);
	},
	afterGetFormJson:function(){
	    if (this.filename != undefined) {
            this.additionalParam.filename = this.filename;
            this.additionalParam.savename = this.savename;
	    }
	},
    initEvent: function() {
		var _this=this;
		var thisid='#'+this.id;	
		_this.isclick = true;
		
		$(thisid+'_save').live('click',function(){	
		    $("#UploadAttachment").uploadifyUpload();
		});
		$(thisid+'_cancle').live('click',function(){			
			_this.hide();
		});
    },
    initUpload:function(recordid){
        $('#upload').empty();
        $('#upload').append('<input type="file" id="UploadAttachment" name="UploadAttachment">');
        //上传附件Flash
        $("#UploadAttachment").uploadify({
            uploader: '/js/Plug/uploadify.swf',
            script: '/service/logic/ShowListLitigation.ashx?op=lituploadattach',
            cancelImg: '/images/cancel.png',
            buttonImg:'/images/fileupload.png', 
            scriptData:{recordid:recordid},
            auto: false,
            multi: false,
            sizeLimit: 1048576,
            height: 24,
            width: 190,
            fileDesc: '支持格式:xls,doc,pdf,rar,zip,jpg,xlsx,docx',  
            fileExt: '*.xls;*.doc;*.pdf;*.rar;*.zip;*.jpg;*.xlsx;*.docx', 
            wmode:'transparent',
            onClick: function(){
                _this.isclick = false;
            },
            onSelectCancel: function(){
                _this.isclick = true;
            },
            onComplete: function(event, queueID, fileObj, response, data) {
                if(response){
					try{
						eval("var json="+response);
						if(json.success==1){
							alert(json.msg);
						}else if(json.success==0){
							alert(json.msg);
						}else{
							alert(json.msg);
							window.location.href=Chenxin.loginUrl;
			            }
			       	}catch(e){
						alert('返回数据格式错误，文件上传失败！');
					}
				}
            },
            onError: function(event, queueID, fileObj, errorObj) {
                alert("文件:" + fileObj.name + "上传失败("+errorObj.info+")");
            },
            onCancel: function(event, queueID, fileObj) {
                _this.isclick = true;
            }
        });
    },
	initComponent:function(){
		Chenxin.UI.UploadAttachForm.superclass.initComponent.call(this);
	}
});


Chenxin.FormCommon.UploadAttachForm=function(formID){
	return '<table class="tbl_f"><tr><th>上传附件：</th><td id="upload"><input type="file" name="UploadAttachment" id="UploadAttachment" /></td></tr><tr><td colspan="2"><input type="hidden"  name="RecordId" /><div style="float:right; margin-right:15px;"><a id="' + formID + '_save" class="btn_n fl" href="#"><span>确定</span></a><a id="' + formID + '_cancle"  class="btn_n fl" href="#"><span>取消</span></a></div></td></tr></table>';
};